//
//  SectionView.m
//  sanmuBoom
//
//  Created by 杨森 on 2017/5/16.
//  Copyright © 2017年 sanmu. All rights reserved.
//

#import "SectionView.h"

@interface SectionView()

@property(nonatomic,strong)UIImageView *moreView;
@property(nonatomic,strong)UIView      *lineView;


@end

@implementation SectionView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self =[super initWithFrame:frame]) {
        [self buildViews];
    }
    return self;
}

- (void)buildViews
{
    
    [self addSubview:self.lineView];
    [self addSubview:self.titleLabel];
    [self addSubview:self.moreView];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    CGFloat margin = 15;
    
    WeakSelf(self);
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(weakself);
        make.left.equalTo(weakself.mas_left).offset(margin);
        make.height.mas_equalTo(weakself.Height/3);
        make.width.mas_equalTo(4);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(weakself.lineView);
        make.centerY.equalTo(weakself);
        make.left.equalTo(weakself.lineView.mas_right).offset(10);
    }];
    
    [self.moreView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(weakself.lineView);
        make.centerY.equalTo(weakself);
        make.right.equalTo(weakself.mas_right).offset(-margin);
        make.width.mas_equalTo(30);
    }];
}


- (UIView *)lineView
{
    if (!_lineView) {
        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = [UIColor redColor];
        _lineView.layer.masksToBounds = true;
        _lineView.layer.cornerRadius = 2;
    }
    return _lineView;
}

- (UILabel *)titleLabel
{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.font = BOLDFONT(15);
        _titleLabel.textColor = [UIColor blackColor];
        _titleLabel.textAlignment = NSTextAlignmentLeft;
    }
    return _titleLabel;
}

- (UIImageView *)moreView
{
    if (!_moreView) {
        _moreView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Home_more"]];
        _moreView.contentMode = UIViewContentModeCenter;
    }
    return _moreView;
}

@end
